package com.baselibrary.libs.design_mode.Observable_demo.Observer;

import com.baselibrary.libs.Utils.netUtils.NoHttp.queue.Request_netWork;
import com.baselibrary.libs.Utils.netUtils.NoHttp.queue.Request_netWork_error;

import java.util.Observable;

/**
 * Created by 35876 于萌萌
 * 创建日期: 21:45 . 2017年02月26日
 * 描述:
 * <p>
 * <p>
 * 备注:
 */

public class MyObserver<T> extends BaseObserver {
    Class<T> clazz;
    public MyObserver(Observable data,Class<T> clazz ,CallBack callBack) {
        super(data, callBack);
        this.clazz = clazz;
    }



    @Override
    public T getBean(Observable observable) {

        try {
                T T = ((Request_netWork) observable).getJsonObject().toJavaObject(clazz);
                return T;
            }
        catch (Exception e){
            Request_netWork_error error = ((Request_netWork) observable).getError();
            error.setMsg("类型转换错误");
            mBack.failure(error);
        }


        return null;
    }

    @Override
    public T getCache(Observable observable) {

        try {
            T T = ((Request_netWork) observable).getJsonObject().toJavaObject(clazz);
            return T;
        }
        catch (Exception e){
            return null;
        }



    }

}
